grammar gdx;

file: node+;

node: openBlock block* endBlock;
openBlock: '<' ID attr* '>';
block: node | value;
endBlock: '</' ID '>';
attr: ID '=' STRING_;

// ?覆盖的可能性?
INT: SIGN? DIGIT+;
DIGIT: [0-9];

// instance(p1,p2);
instance: ID '(' value (',' value)* ')';
// { "key1' : v1 , 'key2' : v2 }
dictionary: '{' pair (',' pair)* '}';
// 字典的key可能省略双引号
pair: STRING_ ':' value | ID ':' value;
// [ v1, v2, v3 ]
array: '[' value (',' value?)* ']';

value:
	INT
	| FLOAT_
	| STRING_
	| dictionary
	| array
	| instance
	| 'true'
	| 'false'
	| 'null';

// ID
ID: NameStartChar NameChar*;
NameChar: NameStartChar | '/';
NameStartChar: CHAR | '_' | DIGIT;
fragment CHAR: ('a' ..'z' | 'A' ..'Z');

// String //xml的"转义
STRING_: '"' ~["]* '"' | '*' ~["]* '*';
// Hex 
HEX: '-'? '0x' HEXNUM (HEXNUM | '_')*;
HEXNUM: [a-fA-F0-9];
// Bin
BIN: '-'? '0b' BINNUM (BINNUM | '_')*;
BINNUM: '0' | '1';
// Number
FLOAT_: SIGN? INT '.' INT;
SIGN: ('+' | '-');

WS: (' ' | '\r' | '\n' | '\t') -> skip;